package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.util.UploadUtil;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/image")
public class ImageController {

    /*
    *上传图片
    * 资源:/images
    * 动作:POST
    * 参数:pic 二进制
    **/
    @RequestMapping("/upload")
    public Object upload(@RequestParam MultipartFile upload){
        Map<String,Object> map = new HashMap<>();
        if(upload.getContentType().startsWith("image") && upload.getSize() > 0){
            String imgUrl = UploadUtil.upload(upload);
            map.put("uploaded","1");
            map.put("url",imgUrl);
        }
        return map;
    }
}
